//
//  TogetherController.m
//  i5db
//
//  Created by iMuse on 15-5-11.
//  Copyright (c) 2015年 mySelf. All rights reserved.
//

#import "TogetherController.h"
#import "AppCenter.h"
#import "PullTableView.h"
#import "TogetherDetailController.h"
#define cellHeight 100

@interface TogetherController ()<UITableViewDataSource,UITableViewDelegate>
{
    PullTableView * pullTableView;
     NSArray       * dataArray;
}

@end

@implementation TogetherController

- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
    if (self) {
       self.title = @"聚会";
         dataArray = [NSArray arrayWithObjects:@"1",@"2",@"3",@"4",@"5", nil];
    }
    return self;
}

-(void)updateViewConstraints
{
    [super updateViewConstraints];
    [pullTableView autoPinEdgesToSuperviewEdgesWithInsets:UIEdgeInsetsMake(0, 0, 0, 0)];
}
-(void) initSearchBar
{
    [super initSearchBar];
}
- (void)viewDidLoad
{
    [super viewDidLoad];
    [self.view setNeedsUpdateConstraints];
    [self initSearchBar];
    [self initView];
}
-(void) initView
{
    
    pullTableView  = [PullTableView newAutoLayoutView];
    [pullTableView setDataSource:self];
    [pullTableView setDelegate:self];
  
    [self.view addSubview:pullTableView];
    
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    
    static NSString* identifier = @"i5dbIndefter";
    UITableViewCell* cell = [tableView dequeueReusableCellWithIdentifier:identifier];
    UILabel         * line          = nil;
    UIImageView     * imageView     = nil;
    UILabel         * projectLabel  = nil;
    UIImageView     * locImageView  = nil;
    UILabel         * locationLabel = nil;
    UIImageView     * timeImageView = nil;
    UILabel         * timeLabel     = nil;
    UIImageView     * personImageView = nil;
    UILabel         * personLabel   = nil;
    tableView.separatorStyle = NO;
    
    if (cell == nil)
    {
        cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault
                                      reuseIdentifier:identifier] ;
        cell.selectionStyle = UITableViewCellSelectionStyleNone;
        
        line = [UILabel newAutoLayoutView];
        line.backgroundColor = [AppCenter color:@"235,235,241,1"];
        [cell.contentView addSubview:line];
        [line autoPinEdgeToSuperviewEdge:ALEdgeLeft withInset:0];
        [line autoPinEdgeToSuperviewEdge:ALEdgeRight withInset:0];
        [line autoPinEdgeToSuperviewEdge:ALEdgeBottom withInset:0];
        [line autoSetDimension:ALDimensionHeight toSize:5];
        
        imageView = [UIImageView newAutoLayoutView];
        imageView.contentMode = UIViewContentModeScaleAspectFit;
        imageView.image = [UIImage imageNamed:@"woman.png"];
        imageView.tag = 1;
        [cell.contentView addSubview:imageView];
        [imageView autoPinEdgeToSuperviewEdge:ALEdgeLeft withInset:2];
        [imageView autoPinEdgeToSuperviewEdge:ALEdgeTop withInset:2];
        [imageView autoPinEdgeToSuperviewEdge:ALEdgeBottom withInset:7];
        [imageView autoSetDimension:ALDimensionWidth toSize:cell.contentView.frame.size.width/4];
        
        projectLabel = [UILabel newAutoLayoutView];
        projectLabel.font = [UIFont fontWithName:fontName size:14];
        projectLabel.numberOfLines = 0;

        projectLabel.text = @"一场只属于单身贵族的Party【北京单身精品聚餐】";
        projectLabel.tag = 2;
        [cell.contentView addSubview:projectLabel];
        [projectLabel autoPinEdge:ALEdgeLeft toEdge:ALEdgeRight ofView:imageView withOffset:5];
        [projectLabel autoPinEdgeToSuperviewEdge:ALEdgeTop withInset:5];
        [projectLabel autoPinEdgeToSuperviewEdge:ALEdgeRight withInset:10];
        [projectLabel autoSetDimension:ALDimensionHeight toSize:cellHeight/2];
        
        locImageView = [UIImageView newAutoLayoutView];
        locImageView.image = [UIImage imageNamed:@"group_card_distance.png"];
        [cell.contentView addSubview:locImageView];
        [locImageView autoPinEdge:ALEdgeTop toEdge:ALEdgeBottom ofView:projectLabel withOffset:0];
        [locImageView autoPinEdge:ALEdgeLeft toEdge:ALEdgeRight ofView:imageView withOffset:5];
        [locImageView autoSetDimensionsToSize:CGSizeMake(10, 12)];
        
        locationLabel = [UILabel newAutoLayoutView];
        locationLabel.tag = 3;
        locationLabel.text = @"欢乐谷";
        
        locationLabel.font = [UIFont systemFontOfSize:12];
        locationLabel.textColor = [AppCenter color:@"126,126,126,1"];
        [cell.contentView addSubview:locationLabel];
        [locationLabel autoPinEdge:ALEdgeLeft toEdge:ALEdgeRight ofView:locImageView withOffset:5];
        [locationLabel autoPinEdge:ALEdgeTop toEdge:ALEdgeBottom ofView:projectLabel withOffset:0];
        [locationLabel autoPinEdgeToSuperviewEdge:ALEdgeRight withInset:10];
        [locationLabel autoSetDimension:ALDimensionHeight toSize:12];
        
        timeImageView = [UIImageView newAutoLayoutView];
        timeImageView.image = [UIImage imageNamed:@"mqz_ugc_btn_time.png"];
        [cell.contentView addSubview:timeImageView];
        [timeImageView autoPinEdge:ALEdgeLeft toEdge:ALEdgeRight ofView:imageView withOffset:5];
        [timeImageView autoPinEdge:ALEdgeTop toEdge:ALEdgeBottom ofView:locImageView withOffset:5];
        [timeImageView autoSetDimensionsToSize:CGSizeMake(10, 10)];
        
        timeLabel     = [UILabel newAutoLayoutView];
        timeLabel.tag = 4;
        timeLabel.text = @"周日 2015/12/23";
        timeLabel.font = locationLabel.font;
        timeLabel.textColor = locationLabel.textColor;
        [cell.contentView addSubview:timeLabel];
        [timeLabel autoPinEdge:ALEdgeLeft toEdge:ALEdgeLeft ofView:locationLabel withOffset:0];
        [timeLabel autoPinEdge:ALEdgeTop toEdge:ALEdgeBottom ofView:locationLabel withOffset:5];
        [timeLabel autoSetDimension:ALDimensionHeight toSize:10];
        [timeLabel autoSetDimension:ALDimensionWidth toSize:100];
        
        personLabel = [UILabel newAutoLayoutView];
        personLabel.tag = 5;
        personLabel.text = @"160";
        personLabel.font = locationLabel.font;
        personLabel.textColor = locationLabel.textColor;
        [cell.contentView addSubview:personLabel];
        [personLabel autoPinEdgeToSuperviewEdge:ALEdgeRight withInset:10];
        [personLabel autoPinEdge:ALEdgeTop toEdge:ALEdgeBottom ofView:locationLabel withOffset:5];
        [personLabel autoSetDimension:ALDimensionHeight toSize:10];
        
        personImageView = [UIImageView newAutoLayoutView];
        personImageView.image = [UIImage imageNamed:@"circle_new_friend_empty.png"];
        [cell.contentView addSubview:personImageView];
        [personImageView autoPinEdge:ALEdgeRight toEdge:ALEdgeLeft ofView:personLabel withOffset:0];
        [personImageView autoPinEdge:ALEdgeTop toEdge:ALEdgeBottom ofView:locationLabel withOffset:5];
        [personImageView autoSetDimensionsToSize:CGSizeMake(10, 10)];
        
        
    }else
    {
        
        
    }
    
    return cell;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    
    return dataArray.count;
    
}

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
    
    return cellHeight;
}

-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    TogetherDetailController* controller = [[TogetherDetailController alloc] init];
    [self.navigationController pushViewController:controller animated:YES];
}






















- (void)didReceiveMemoryWarning
{
    [super didReceiveMemoryWarning];
   
}



@end
